package yw.nmh.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import yw.nmh.ranchInfo.dto.RanchAddDTO;
import yw.nmh.ranchInfo.dto.RanchBaseDTO;
import yw.nmh.ranchInfo.vo.RanchBaseVO;
import yw.nmh.ranchInfo.vo.RanchVO;
import yw.nmh.result.R;
import yw.nmh.service.RanchInfoService;

import java.util.List;

@RestController
@Slf4j
@Tag(name = "牧场管理", description = "牧场管理相关接口")
@RequestMapping("/ranch")
public class RanchInfoController {
    @Resource
    private RanchInfoService ranchInfoService;
    @PostMapping("/ranchs")
    @Operation(summary = "查询牧场", description = "查询牧场")
    public R ranchs(@RequestBody RanchBaseDTO ranchBaseDTO){
        Page<RanchBaseVO> ranchBaseVOPage = ranchInfoService.listRanch(ranchBaseDTO);
        return R.OK(ranchBaseVOPage);
    }

    @GetMapping("/ranch")
    @Operation(summary = "返回牧场详情", description = "返回牧场详情")
    public R ranch(@RequestParam Integer id){
        RanchVO ranch = ranchInfoService.ranch(id);
        return R.OK(ranch);
    }

    @PostMapping("/addRanch")
    @Operation(summary = "增加牧场", description = "增加牧场")
    public R ranchAdd(@RequestBody RanchAddDTO ranchAddDTO){
        return ranchInfoService.addRanch(ranchAddDTO)?R.OK("添加成功"):R.FAIL("添加失败");
    }

    @PostMapping("/updateRanch")
    @Operation(summary = "修改牧场", description = "修改牧场")
    public R ranchUpdate(@RequestBody RanchAddDTO ranchAddDTO){
        return ranchInfoService.addRanch(ranchAddDTO)?R.OK("修改成功"):R.FAIL("修改失败");
    }


}
